package com.qf.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.pojo.DtsRegion;
import com.qf.service.RegionService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin("*")
@RequestMapping("/region")
public class RegionController {


    @Autowired
    private RegionService regionService;

    @RequestMapping("/list")
    public Object list(String name,String code,
                        @RequestParam(defaultValue = "1") Integer page,
                        @RequestParam(defaultValue = "10") Integer limit){

        IPage<DtsRegion> resultPage = regionService.queryAllRegion(name, code, page, limit);

        List<DtsRegion> list = resultPage.getRecords();

        long total = resultPage.getTotal();

        Map<String, Object> data = new HashMap<>();
        data.put("total",total);
        data.put("items",list);

        return ResponseUtil.ok(data);


    }
}
